package figure8.GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.sound.midi.Instrument;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.sampled.Mixer;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.Border;

import figure8.Controller;
import figure8.MIDITrack;
import figure8.Rec;

public class RecMIDISelectInstrumentWindow extends JDialog {
	int selectedItem;
	public RecMIDISelectInstrumentWindow (final MainWindow window, final Instrument[] instruments, final Rec rec) {
		super();

		this.setLocation(window.getFrame().getX() + 80, window.getFrame()
				.getY() + 120);

		Box column = Box.createVerticalBox();
		
		final RecMIDISelectInstrumentWindow  audioWin = this;
		
		// Add the drop down list with it's elements
		Border rowBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
		final JComboBox combo = new JComboBox(instruments);
		combo.setBorder(rowBorder);
		
		JButton submit = new JButton("Start Recording");
		combo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				selectedItem = combo.getSelectedIndex();
				rec.MIDISelectInstrument(selectedItem);
			}
		});
		
		submit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				audioWin.dispose();
				rec.startRecording();
			}
		});
		
		column.add(combo);
		column.add(submit);
		JPanel settings = new JPanel();
		settings.add(column);
		settings.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		this.getContentPane().add(settings);
		this.pack();
		this.setVisible(true);
	}
	
	public int getMixer()
	{
		return selectedItem;
	}
}